//
//  JoinViewController.m
//  Shine
//
//  Created by 王斌 on 16/3/19.
//  Copyright © 2016年 王斌. All rights reserved.
//

#import "JoinViewController.h"
#import "TalkViewController.h"
@interface JoinViewController ()
@property (strong, nonatomic) IBOutlet UITextField *userName;

@property (strong, nonatomic) IBOutlet UITextField *passWord;


@end

@implementation JoinViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)joinAction:(id)sender {
    [[EaseMob sharedInstance].chatManager asyncRegisterNewAccount:self.userName.text password:self.passWord.text withCompletion:^(NSString *username, NSString *password, EMError *error) {
        if (!error) {
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"成功" message:@"注册成功" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *alert = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            [alertController addAction:alert];
            [self presentViewController:alertController animated:YES completion:^{
                
            }];

        }else{
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"失败" message:error.description preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *alert = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            [alertController addAction:alert];
            [self presentViewController:alertController animated:YES completion:^{
                
            }];

        }
    } onQueue:nil];
}
- (IBAction)landingAction:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        TalkViewController *talk = [[TalkViewController alloc] init];
        talk.userName = self.userName.text;
        talk.passWord = self.passWord.text;
        [talk showHUD];

    }];
    
        
//    [[EaseMob sharedInstance].chatManager asyncLoginWithUsername:self.userName.text password:self.passWord.text completion:^(NSDictionary *loginInfo, EMError *error) {
//        if (!error && loginInfo) {
//            
//            [[NSUserDefaults standardUserDefaults]setObject:self.userName.text forKey:@"userName"];
//            [[NSUserDefaults standardUserDefaults]setObject:self.passWord.text forKey:@"passWord"];
////
//            NSNotification *notification =[NSNotification notificationWithName:@"LoggedIn" object:nil userInfo:[NSDictionary dictionaryWithObject:@"退出" forKey:@"LoggedIn"]];
//            //通过通知中心发送通知
//            [[NSNotificationCenter defaultCenter] postNotification:notification];
//            [[NSUserDefaults standardUserDefaults] setObject:@"Yes" forKey:@"AutoJoin"];
//
//            [self dismissViewControllerAnimated:YES completion:^{
//                
//            }];
//           
//        }else{
//            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"错误" message:error.description preferredStyle:UIAlertControllerStyleAlert];
//            UIAlertAction *alert = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//                
//            }];
//            [alertController addAction:alert];
//            [self presentViewController:alertController animated:YES completion:^{
//                
//            }];
//            
//        }
//    } onQueue:nil];
}
- (IBAction)backAction:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
